;*******************************************************************************
; Title:	AddResM
; Author:	Paul Clifford
; Copyright:	(C) Paul Clifford 1995
; Version:	1.00, 1 Dec 1995
; Purpose:	Adds a directory to ResourceFS
;
; Modified by:	Philip Ludlam
; Changes:	Made it 32-bit compatible
;		Fixed bugs in 32-bit conversion.
;		Optimised the module.
;		Added facility to add a single file.
; Version	1.05, 4 September 2003
;
;*******************************************************************************
; This program is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the Free
; Software Foundation; either version 2 of the License, or (at your option)
; any later version.
;
; This program is distributed in the hope that it will be useful, but WITHOUT
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more
; details.
;
; You should have received a copy of the GNU General Public License along with
; this program; if not, write to the Free Software Foundation, Inc., 59 Temple
; Place - Suite 330, Boston, MA 02111-1307, USA
;
;*******************************************************************************


		TTL	> AddResM

		GET	OSLib:oslib.hdr.types
		GET	OSLib:oslib.hdr.OS
		GET	OSLib:oslib.hdr.ResourceFS
		GET	AsmLib2:hdr.RegsBoth
		GET	AsmLib2:hdr.Macros

		AREA	|Module_Base|, CODE

		EXPORT	Module_Start
		EXPORT	Module_End


Module_Start
		DCD	0				; Start offset
		DCD	Initialise	- Module_Start	; Initialisation offset
		DCD	Finalise	- Module_Start	; Finalisation offset
		DCD	ServiceCode	- Module_Start	; Service call handler offset
		DCD	0				; Title (added later)
		DCD	0				; Help (added later)
		DCD	0
		DCD	0				; SWI chunk base number
		DCD	0				; SWI handler code offset
		DCD	0				; SWI decoding table offset
		DCD	0				; SWI decoding code offset
		DCD	0				; MessageTrans file
		DCD	ModuleFlags	- Module_Start	;  32-bit OK flag

ModuleFlags
		DCD	1				; 32-bit compatible

Initialise	DOSIGNATURE
		MOV	r1, lr
		ADR	r0, ResourceFS_File_Data
		SWI	XResourceFS_RegisterFiles
		MOV	pc, r1

Finalise	DOSIGNATURE
		MOV	r1, lr
		ADR	r0, ResourceFS_File_Data
		SWI	XResourceFS_DeregisterFiles
		MOV	pc, r1

ServiceTable	DCD	0
		DCD	ServiceDo	- Module_Start
		DCD	Service_ResourceFSStarting	; &60
		DCD	0

		DCD	ServiceTable	- Module_Start

ServiceCode	MOV	r0, r0
		TEQ	r1, #Service_ResourceFSStarting	; cmp r1, #&60
		MOVNE	pc, lr				; if not: exit

ServiceDo	STMFD	r13!, {r0, lr}
		ADR	r0, ResourceFS_File_Data
		MOV	lr, pc				; emulate BL
		MOV	pc, r2				; and call ResourceFS code
		LDMFD	r13!, {r0, pc}			; restore registers


ResourceFS_File_Data


Module_End

	END
